** Command codes to reproduce the results in "Disagreement and Deliberation: Evidence from Three Deliberative Mini-Publics"
** Authors: Kimmo Grönlund, Kaisa Herne, Kim Strandberg and Peter Söderlund
** Dataset: Citizen Deliberation on Immigration: Survey Data 2012
** Source: Full dataset (.csa, .por) available via the Finnish Social Science Data Archive, http://urn.fi/urn:nbn:fi:fsd:T-FSD2958
** Note: The analyses below are based on a reduced version of the dataset available via the Finnish Social Science Data Archive


** Open Nuclear power file
use "...\Immigration data.dta"

** Recode variables

* Recode - Attitudes toward immigration (scale 0 to 10)
recode t1_v1 t1_v2 t1_v3 (99=.) (.a=.) 
recode t1_v4 t1_v5 t1_v6 t1_v7 t1_v8 t1_v9 t1_v10 t1_v11 t1_v12 t1_v13 t1_v14 (99=.) (.a=.)
recode t1_v4 t1_v5 t1_v6 t1_v7 t1_v8 t1_v9 t1_v10 t1_v11 t1_v12 t1_v13 t1_v14 (1=0) (2=3.33) (3=6.66) (4=10)
recode t1_v2 (0=10) (1=9) (2=8) (3=7) (4=6) (5=5) (6=4) (7=3) (8=2) (9=1) (10=0)
recode t1_v5 t1_v7 t1_v8 t1_v10 (0=10) (3.33=6.66) (6.66=3.33) (10=0)

* Identify missing values - Attitudes toward immigration (scale 0 to 10)
summ t1_v1 t1_v2 t1_v3  t1_v4 t1_v5 t1_v6 t1_v7 t1_v8 t1_v9 t1_v10 t1_v11 t1_v12 t1_v13 t1_v14
mvpatterns  t1_v1 t1_v2 t1_v3  t1_v4 t1_v5 t1_v6 t1_v7 t1_v8 t1_v9 t1_v10 t1_v11 t1_v12 t1_v13 t1_v14
egen meant1_v1 = mean(t1_v1)
egen meant1_v2 = mean(t1_v2)
egen meant1_v3 = mean(t1_v3)
egen meant1_v4 = mean(t1_v4)
egen meant1_v5 = mean(t1_v5)
egen meant1_v6 = mean(t1_v6)
egen meant1_v7 = mean(t1_v7)
egen meant1_v8 = mean(t1_v8)
egen meant1_v9 = mean(t1_v9)
egen meant1_v10 = mean(t1_v10)
egen meant1_v11 = mean(t1_v11)
egen meant1_v12 = mean(t1_v12)
egen meant1_v13 = mean(t1_v13)
egen meant1_v14 = mean(t1_v14)

* Replace missing values - Attitudes toward immigration (scale 0 to 10)
replace t1_v1 = meant1_v1 if t1_v1 == .
replace t1_v2 = meant1_v2 if t1_v2 == .
replace t1_v3 = meant1_v3 if t1_v3 == .
replace t1_v4 = meant1_v4 if t1_v4 == .
replace t1_v5 = meant1_v5 if t1_v5 == .
replace t1_v6 = meant1_v6 if t1_v6 == .
replace t1_v7 = meant1_v7 if t1_v7 == .
replace t1_v8 = meant1_v8 if t1_v8 == .
replace t1_v9 = meant1_v9 if t1_v9 == .
replace t1_v10 = meant1_v10 if t1_v10 == .
replace t1_v11 = meant1_v11 if t1_v11 == .
replace t1_v12 = meant1_v12 if t1_v12 == .
replace t1_v13 = meant1_v13 if t1_v13 == .
replace t1_v14 = meant1_v14 if t1_v14 == .

* Recode - Quality of deliberation
gen opinionchange1 = t4_v67
gen opinionchange2 = t4_v78
gen moreknowledge = t4_v71
gen morereadiness = t4_v72
gen moredeliberation = t4_v22_g
gen participatefuture = t4_v73
gen pleasantexperience = t4_v68
gen difficult = t4_v81
gen motivated = t4_v82
gen respect1 = t4_v70
gen respect2 = t4_v74
gen respect3 = t4_v80
gen ownopinions = t4_v69
recode opinionchange1 opinionchange2 moreknowledge morereadiness moredeliberation participatefuture pleasantexperience difficult motivated respect1 respect2 respect3 ownopinions (1=1) (2=2) (5=.) (99=.) (3=3) (4=4)
recode opinionchange1 opinionchange2 moreknowledge morereadiness moredeliberation participatefuture pleasantexperience difficult motivated respect1 respect2 respect3 ownopinions (1=0) (2=3.33) (3=6.66) (4=10)
recode difficult respect1 respect2 (0=10) (3.33=6.66) (6.66=3.33) (10=0)

* Identify missing values - Quality of deliberation (scale 0 to 10)
mvpatterns opinionchange1 opinionchange2 moreknowledge morereadiness moredeliberation participatefuture pleasantexperience difficult motivated respect1 respect2 respect3 ownopinions
egen dep1_missing = rowmiss(moreknowledge morereadiness pleasantexperience participatefuture ownopinions)
egen meanopinionchange1 = mean(opinionchange1)
egen meanopinionchange2 = mean(opinionchange2)
egen meanmoreknowledge = mean(moreknowledge)
egen meanmorereadiness = mean(morereadiness)
egen meanmoredeliberation = mean(moredeliberation)
egen meanparticipatefuture = mean(participatefuture)
egen meanpleasantexperience = mean(pleasantexperience)
egen meandifficult = mean(difficult)
egen meanmotivated = mean(motivated)
egen meanrespect1 = mean(respect1)
egen meanrespect2 = mean(respect2)
egen meanrespect3 = mean(respect3)
egen meanownopinions = mean(ownopinions)

* Replace missing values - Quality of deliberation (scale 1 to 10)
egen dep1_rowmean = rmean(moreknowledge morereadiness moredeliberation participatefuture pleasantexperience)
replace moreknowledge = meanmoreknowledge if moreknowledge == .
replace morereadiness = meanmorereadiness if morereadiness == .
replace moredeliberation = meanmoredeliberation if moredeliberation == .
replace participatefuture = meanparticipatefuture if participatefuture == .
replace pleasantexperience = meanpleasantexperience if pleasantexperience == .
replace opinionchange1 = meanopinionchange1 if opinionchange1 == .
replace opinionchange2 = meanopinionchange2 if opinionchange2 == .
replace difficult = meandifficult if difficult == .
replace motivated = meanmotivated if motivated == .
replace respect1 = meanrespect1 if respect1 == .
replace respect2 = meanrespect2 if respect2 == .
replace respect3 = meanrespect3 if respect3 == .
replace ownopinions = meanownopinions if ownopinions == .

** Factor analysis

* Factor analysis - Attitudes toward immigration (scale 0 to 10)
summ t1_v1 t1_v2 t1_v3 t1_v4 t1_v5 t1_v6 t1_v7 t1_v8 t1_v9 t1_v10 t1_v11 t1_v12 t1_v13 t1_v14
polychoric t1_v1 t1_v2 t1_v3 t1_v4 t1_v5 t1_v6 t1_v7 t1_v8 t1_v9 t1_v10 t1_v11 t1_v12 t1_v13 t1_v14
display r(sum_w)
global N = r(sum_w)
matrix r = r(R)
factormat r, n($N) factors(1) pcf

* Factor analysis - Quality of deliberation index (scale 0 to 10)
summ moreknowledge morereadiness moredeliberation participatefuture pleasantexperience
polychoric moreknowledge morereadiness moredeliberation participatefuture pleasantexperience
display r(sum_w)
global N = r(sum_w)
matrix r = r(R)
factormat r, n($N) factors(1) pcf

** Generate means and standard deviations

* Generate mean - Attitudes toward immigration (scale 1 to 10)
generate immigration_mean = (t1_v1 + t1_v2 + t1_v3 + t1_v4 + t1_v5 + t1_v6 + t1_v7 + t1_v8 + t1_v9 + t1_v10 + t1_v11 + t1_v12 + t1_v13 + t1_v14) / 14

* Generate mean - Quality of deliberation (scale 0 to 10)
generate index_mean = (moreknowledge + morereadiness + pleasantexperience + participatefuture + ownopinions) / 5

* Standard deviation by group - Attitudes toward immigration (scale 1 to 10)
bys group: asrol immigration_mean, stat(sd) xf(focal)
rename sd_immigration_mean tabledisagreement
summ tabledisagreement
generate tabledisagreement_c = tabledisagreement - 1.5
generate tabledisagreement_c_squared = tabledisagreement_c * tabledisagreement_c

* Group mean centering - Attitudes toward immigration (scale 1 to 10)
bys group: asrol immigration_mean, stat(mean) xf(focal)
generate dimmigration_mean = immigration_mean - mean_immigration_mean
generate dimmigration_mean_abs = abs(dimmigration_mean)
summ dimmigration_mean_abs
generate dimmigration_mean_abs_c = dimmigration_mean_abs - 1.4

** Empirical analyses

* Table 3 - Immigration - Descriptive statistics
preserve
collapse (mean) sdtabledisagreement=tabledisagreement (mean) meanimmigration_mean=immigration_mean, by(group)
sort sdtabledisagreement
tab sdtabledisagreement
sort meanimmigration_mean
tab meanimmigration_mean
restore

* Table 4 - Immigration - Mean and standard deviation - Attitudes toward Swedish language (scale 1 to 10)
tabstat index_mean, statistics(mean sd)

* Table 4 - Immigration - Cronbach's alpha - Quality of deliberation index (scale 0 to 10)
alpha moreknowledge morereadiness pleasantexperience participatefuture ownopinions

* Table 6 - Linear model - Adjusted R2 - OLS regressions without cluser-robust standard errors
regress index_mean c.tabledisagreement_c c.dimmigration_mean_abs_c i.treatment, 

* Table 6 - Curvilinear model - Adjusted R2 - OLS regressions without cluser-robust standard errors
regress index_mean c.tabledisagreement_c##c.tabledisagreement_c c.dimmigration_mean_abs_c##c.dimmigration_mean_abs_c i.treatment, 

* Table 6 - Linear model - Coefficients - OLS regression with cluser-robust standard errors
regress index_mean c.tabledisagreement_c c.dimmigration_mean_abs_c i.treatment, vce(cluster group)

* Table 6 - Curvilinear model - Coefficients - OLS regression with cluser-robust standard errors
regress index_mean c.tabledisagreement_c##c.tabledisagreement_c c.dimmigration_mean_abs_c##c.dimmigration_mean_abs_c i.treatment, vce(cluster group)

* Figure 3
regress index_mean c.tabledisagreement_c##c.tabledisagreement_c c.dimmigration_mean_abs_c##c.dimmigration_mean_abs_c i.treatment, vce(cluster group)
margins, at(tabledisagreement_c=(-1.08(0.01)1.83)) post coeflegend
lincom (_b[1._at] - _b[261._at])
marginsplot, legend(title("", color(black) size(medium))) recast(line) recastci(rarea) plot1opts(lpattern(solid) lcolor(midblue%100) lwidth(thick)) ci1opts(lpattern(solid) color(midblue%30) lcolor(midblue%5) lwidth(thin)) ylabel(5(1)10, angle(90) nogrid glcolor(gs14) labsize(4) format(%9.0f)) ytitle("Process Satisfaction Index", size(5) height(6)) yscale(noline) xscale(noline) xlabel(-1.5 "0" -0.5 "1" 0.5 "2" 1.5 "3" 2.5 "4" 3.5 "5", labsize(4) format(%3.1f)) xtitle("Group-level Disagreement", size(5) height(6)) graphregion(fcolor(white) lcolor(white) lwidth(thick)) plotregion(fcolor(white) lcolor(black) lwidth(thin)) title("") subtitle("Deliberation on Immigration", size(5) color(black)) xsize(8) ysize(8) 

* Figure 4
regress index_mean c.tabledisagreement_c##c.tabledisagreement_c c.dimmigration_mean_abs_c##c.dimmigration_mean_abs_c i.treatment, vce(cluster group)
margins, at(dimmigration_mean_abs_c=(-1.4(0.01)4.05)) post coeflegend
lincom (_b[1._at] - _b[49._at])
marginsplot, legend(title("", color(black) size(medium))) recast(line) recastci(rarea) plot1opts(lpattern(solid) lcolor(midblue%100) lwidth(thick)) ci1opts(lpattern(solid) color(midblue%30) lcolor(midblue%5) lwidth(thin)) ylabel(5(1)10, angle(90) nogrid glcolor(gs14) labsize(4) format(%9.0f)) ytitle("Process Satisfaction Index", size(5) height(6)) yscale(noline) xscale(noline) xlabel(-1.4 "0" -0.4 "1" 0.6 "2" 1.6 "3" 2.6 "4" 3.6 "5" 4.6 "6", labsize(4) format(%3.0f)) xtitle("Individual-level Disagreement", size(5) height(6)) graphregion(fcolor(white) lcolor(white) lwidth(thick)) plotregion(fcolor(white) lcolor(black) lwidth(thin)) title("") subtitle("Deliberation on Immigration", size(5) color(black)) xsize(8) ysize(8)

* Power analysis
power oneslope 0 -0.65, sdx(0.58) sdy(1.30) power(.8)
power oneslope 0 -0.65, sdx(0.58) sdy(1.30) power(.9)
power oneslope 0, n(207) sdx(0.58) sdy(1.30) power(.8)
power oneslope 0, n(207) sdx(0.58) sdy(1.30) power(.9)

